#!/bin/bash
#
# Example Shared File backup command script 
#         This example uses tar to archive all the necessary files
#
#  MYLOGPATH, MYFILESPATH and MYCONFIGURATION should be subsituted with
#  the correct values for your workstation.
#

do_dbbackupfailed()
{
   echo "Error during dbbackup test. bck aborted."
   exit 1
}

do_genlogfailed()
{
   echo "Error while generating new log file. bck aborted."
   exit 2
}

do_backupfailed()
{
   rm MYLOGPATH/log.dat
   mv MYLOGPATH/log.old MYLOGPATH/log.dat
   echo "Error during files backuo. bck aborted"
   exit 3
}

# unload the Shared File Server
ehcfree shfile##

# Perform the dbbackup test, to see if we can back up the necessary files
dbbackup
if [ $? -ne 0 ] ; then
   do_dbbackupfailed
fi

# Before backing up it would be good to generate a new log file.
# The existing log file will be renamed log.old
genlog 1 1
if [ $? -ne 0 ] ; then
   do_genlogfailed
fi

# Copy the existing (log.old) to the backup point
# Use tar to create an archive on /dev/fd0 (floppy drive)
# Use full pathnames when specifying files to archive
tar cMvf /dev/fd0 MYLOGPATH/log.old
if [ $? -ne 0 ] ; then
   do_backupfailed
fi

# Copy the dbd and pcb definitions to the backup point. 
# Note this needs only to be done once, as the dbd and pcb
# files do not change, unless updtconf has been used.
tar rMvf /dev/fd0 FULLPATH/MYCONFIGURATION.dbd
if [ $? -ne 0 ] ; then
   do_backupfailed
fi

tar rMvf /dev/fd0 FULLPATH/MYCONFIGURATION.pcb
if [ $? -ne 0 ] ; then
   do_backupfailed
fi

# No save the data files.  The files are stored in 
# a directory given at customisation (DBDPATH6).
tar rMvf /dev/fd0 MYFILES/*.*
if [ $? -ne 0 ] ; then
   do_backupfailed
fi

# All Done
echo "Backup process completed"
